package com.neuedu.yyzxproject.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.neuedu.yyzxproject.mapper.NurseLevelMapper;
import com.neuedu.yyzxproject.pojo.Nursecontent;
import com.neuedu.yyzxproject.pojo.Nurselevel;
import com.neuedu.yyzxproject.service.NurseLevelService;
import com.neuedu.yyzxproject.vo.PageInfoVo;
import com.neuedu.yyzxproject.vo.PageResponseVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class NurseLevelServiceImpl implements NurseLevelService {
    @Autowired
    private NurseLevelMapper nurseLevelMapper;
    private <T> PageResponseVo<T> getPageResponse(List<T> list) {
        PageInfo<T> pageInfo = new PageInfo<>(list);
        long total = pageInfo.getTotal();
        int pageSize = pageInfo.getPageSize();
        int currentPage = pageInfo.getPageNum();
        int pages = pageInfo.getPages();
        List<T> dataList = pageInfo.getList();

        PageResponseVo<T> pageResponseVo = new PageResponseVo<>();
        pageResponseVo.setData(dataList);
        pageResponseVo.setCurrentPage(currentPage);
        pageResponseVo.setPageSize(pageSize);
        pageResponseVo.setTotal(total);
        pageResponseVo.setPageNum(pages);
        return pageResponseVo;
    }

    @Override
    public PageResponseVo<Nurselevel> findNurselevel(PageInfoVo pageInfoVo) {
        PageHelper.startPage(pageInfoVo.getCurrentPage(), pageInfoVo.getPageSize());
        List<Nurselevel> nurselevel = nurseLevelMapper.findNurselevel();
        return getPageResponse(nurselevel);
    }

    @Override
    public int addNurselevel(Nurselevel nurselevel) {
        return nurseLevelMapper.addNurselevel(nurselevel);
    }

    @Override
    public int modifyNurselevelStatus(Nurselevel nurselevel) {
        return nurseLevelMapper.modifyNurselevelStatus(nurselevel);
    }

    @Override
    public PageResponseVo<Nursecontent> queryNursingProject(PageInfoVo pageInfoVo,Nursecontent nursecontent) {
        PageHelper.startPage(pageInfoVo.getCurrentPage(), pageInfoVo.getPageSize());
        List<Nursecontent> nursecontents = nurseLevelMapper.queryNursingProject(nursecontent);
        return getPageResponse(nursecontents);
    }

    @Override
    public PageResponseVo<Nursecontent> queryNursingProjectByLevel(PageInfoVo pageInfoVo, Nurselevel nurselevel) {
        PageHelper.startPage(pageInfoVo.getCurrentPage(), pageInfoVo.getPageSize());
        List<Nursecontent> nursecontents = nurseLevelMapper.queryNursingProjectByLevel(nurselevel);
        return getPageResponse(nursecontents);
    }

    @Override
    public int deleteProjectInLevel(Integer levelId, Integer itemId) {
        return nurseLevelMapper.deleteProjectInLevel(levelId, itemId);
    }
}
